package com.lsb.config;

import com.lsb.dao.DataDao;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author ：liusibo
 * @description：TODO
 * @date ：2021/4/27 17:36
 */
@Configuration
public class MyConfig implements WebMvcConfigurer {
    @Bean
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }

    @Bean
    public CommandLineRunner commandLineRunner(DataDao dataDao){
        return args -> {
            System.out.println("=============CommandLineStart==========");
            dataDao.pullData();
            System.out.println("=============CommandLineEnd==========");
        };
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedMethods("GET")
                .allowCredentials(true)
                .maxAge(3600)
                .allowedHeaders("*");
    }
}
